package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.model.ClassModel;
import com.example.hyw.szysteam.view.CreateClassDialog;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/6/7.
 */

public class CreateClassPresenter {
    ClassModel classModel=new ClassModel();
    CreateClassDialog createClassDialog;

    public CreateClassPresenter(CreateClassDialog createClassDialog) {
        this.createClassDialog = createClassDialog;
    }

    public void createClass(String email,String classname,String teacher){
        classModel.createClass(email,classname,teacher)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<String>>() {
                    @Override
                    public void accept(HttpResult<String> stringHttpResult) throws Exception {
                        String invitecode=stringHttpResult.getContent();
                        createClassDialog.createSuccess(invitecode);
                    }
                });
    }
}
